package ru.ipo.dces.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: 01.04.11
 * Time: 2:06
 */
public class ResultUtils {

    //TODO make proper html escaping
    public static String map2string(Map<String, String> map) {
        boolean isFirst = true;
        StringBuilder sb = new StringBuilder("<html>");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (isFirst)
                isFirst = false;
            else
                sb.append("<br>");

            sb.append(entry.getKey()).append(": <b>").append(entry.getValue()).append("</b>");
        }

        sb.append("</html>");
        return sb.toString();
    }

    public static HashMap<String, String> newMap(String... keysValues) {
        if (keysValues == null || keysValues.length % 2 != 0)
            throw new IllegalArgumentException("There should be an even number of arguments");
        HashMap<String, String> res = new HashMap<String, String>();
        for (int i = 0; i < keysValues.length; i += 2)
            res.put(keysValues[i], keysValues[i+1]);
        return res;
    }
}
